
import ZoomShow from "../carousel/swiper/ZoomShow.js";
import goodsDetail from '../carousel/detail/shoppingdetail.js'
import StepNumber from "../carousel/swiper/StepNumber.js";
import LStorage from './localtion.js';
import Component from "../carousel/swiper/Component.js";
new LStorage()

class Shopping  extends Component{
   elem;
   colorchange;
   num;
   arrcar;
   inputs;
   nowbuy;
   constructor() {
      super()
      window.addEventListener('load', e => this.loadHandler(e))    
   }
   async loadHandler(e,datas) {
      var ids = window.location.href.split('?')[1];
      var data = await fetch('http://localhost:4020/getdata', {
         method: 'post',
         body: JSON.stringify(ids)
      });
     
      data = await data.json()   
      console.log(data);
      data = data.result[0] 
      data.skuList = JSON.parse(data.skuList)
      new goodsDetail(data);
      this.nowbuy=document.querySelector('.buynow');
      this.nowbuy.addEventListener('click',e=>this.nowbuyHandle(e))
      let step=new StepNumber();   
      step.addEventListener(StepNumber.STEP_CHANGE_EVENT,e=>this.stepChangeHandler(e))
      step.appendTo('.addnum')
      this.inputs=step.elem.querySelector("input");
      this.colorchange=document.querySelector('.colorchange')
     new ZoomShow(data,this.colorchange) 
     this.arrcar=document.querySelector('.caradd')
     this.arrcar.addEventListener('click',e=>this.arrcarHandler(e,data,ZoomShow.m))
   }
   nowbuyHandle(e){
      location.href='./nowbuy.html'
   }
   arrcarHandler(e,data,m){
      var sz=m.get("size");
      var col=m.get('color')
      var s=localStorage.getItem('user');
      if(s){
          location.href='./buycar.html'+"?"+data.productSid+"/"+sz+"/"+col+"/"+this.inputs.value;
      }else{
          alert('您还没有登录，请登录')
          location.href='./login.html'
      }
  }
  stepChangeHandler(e){

  }
}
new Shopping()